// 查找最大field
export const getMaxFieldValue = (arr, field) => {
  let max = -Infinity

  arr.forEach((item) => {
    const fieldValue =
      item[field] &&
      item[field].substring(5) &&
      !isNaN(item[field].substring(5)) &&
      Number(item[field].substring(5))
    if (fieldValue) {
      max = Math.max(max, fieldValue)
    }
    if (item.children && item.children.length > 0) {
      max = Math.max(max, getMaxFieldValue(item.children, field))
    }
  })

  return max === -Infinity ? 'field1' : `field${max + 1}`
}

// 生成field
export const generateFieldName = (field, filedList) => {
  const maxField = getMaxFieldValue(filedList, field)
  return maxField
}
